package jianzhiOffer;
//剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
public class Num68_I_lowestCommonAncestor {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        TreeNode node = root;
        while (true){
            if (node.val > p.val && node.val > q.val){
                node = node.left;
            }else if (node.val < p.val && node.val < q.val){
                node = node.right;
            }else {
                break;
            }

        }
        return node;
    }
}
